<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>业绩中心操作</title>
    <script src="../../res/js/jquery-3.4.1.min.js"></script>
    <script src="../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../res/js/Tools.js"></script>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <link href="../../res/echarts/eleTree.css" rel="stylesheet"/>
    <script src="../../res/echarts/eleTree.js"></script>
    <script src="../../res/js/login_common.js" charset="utf-8"></script>
    <style type="text/css">
        body {
            padding: 10px;
        }
    </style>
</head>
<body>
<form class="layui-form" action="">
    <input type="hidden" id="performanceId" name="performanceId">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">成交人：</label>
            <div class="layui-input-inline">
                <select id="userId" name="userId" lay-verify="required" lay-search="">
                    <option value="">直接选择或搜索选择</option>
                    <option value="1">layer</option>
                    <option value="2">form</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">成交房源</label>
        <div class="layui-input-block">
            <select id="houseId" name="houseId" lay-verify="required" lay-search="">
                <option value="">直接选择或搜索选择</option>
                <option value="1">layer</option>
                <option value="2">form</option>
                <option value="3">layim</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">成交价格</label>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="performanceMoney" id="performanceMoney" lay-verify="required"
                       placeholder="￥（必填）"
                       autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">佣金</label>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="performanceBrokerage" id="performanceBrokerage" lay-verify="required"
                       placeholder="￥（必填）"
                       autocomplete="off"
                       class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">业绩分成</label>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="performanceDivide" id="performanceDivide" lay-verify="required"
                       placeholder="￥（必填）"
                       autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">成交日期</label>
            <div class="layui-input-inline">
                <input type="text" lay-verify="required" name="performanceDate" class="layui-input" id="performanceDate"
                       placeholder="yyyy-MM-dd HH:mm:ss">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">备注：</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" id="performanceRemark"
                      name="performanceRemark"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1" id="sub">立即提交</button>
        </div>
    </div>
</form>
<script>
    layui.use(['form', 'layedit', 'laydate', 'layer'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
        // 修改赋值
        var performanceId = getQueryString("performanceId");

        //日期时间选择器
        laydate.render({
            elem: '#performanceDate'
            , type: 'datetime'
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            var url = "../../performanceAction/addOrUpdate";
            $.post(url, data.field, function (obj) {
                if (obj>0) {
                    window.parent.location.reload();//刷新父页面
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                }
            }, "json");
            return false;
        });

        var url = "../../houseAction/selectAll";
        $.post(url, null, function (obj) {
            $("#houseId").html("<option value=''>直接选择或搜索选择</option>");
            $.each(obj, function (index, item) {
                $("#houseId").append('<option value="' + item.houseId + '">' + item.userName + '-' + item.sectorName + '-' + item.houseArea + '㎡-' + item.housePrice + '￥</option>')
            });
            form.render();
        }, "json");

        var url = "../../userAction/selectAll";
        $.post(url, null, function (obj) {
            $("#userId").html("<option value=''>直接选择或搜索选择</option>");
            $.each(obj, function (index, item) {
                $("#userId").append('<option value="' + item.userId + '">' + item.userName + '</option>')
            });
            form.render();
        }, "json");

        if (performanceId) {
            $("#performanceId").val(performanceId);
            var url = "../../performanceAction/findById";
            var data = {"id": performanceId};
            $.post(url, data, function (obj) {
                $("#userId").val(obj.userId);                            // 员工id
                $("#houseId").val(obj.houseId);                          // 房源id
                $("#performanceMoney").val(obj.performanceMoney);        // 成交价格
                $("#performanceBrokerage").val(obj.performanceBrokerage);// 佣金
                $("#performanceDivide").val(obj.performanceDivide);      // 业绩分成
                $("#performanceDate").val(obj.performanceDate);          // 成交日期
                $("#performanceRemark").val(obj.performanceRemark);      // 备注
                form.render();
            }, "json")
        }
        form.render();
    });

</script>

</body>
</html>